package com.youku.adSDK
{
   import flash.events.EventDispatcher;
   import com.youku.adSDK.view.AdHolderMediator;
   import flash.text.TextField;
   import com.youku.adSDK.view.FrontMediator;
   import com.youku.adSDK.view.BackMediator;
   import com.youku.adSDK.view.PauseMediator;
   import com.youku.adSDK.view.InsertMediator;
   import com.youku.adSDK.view.OverlayMediator;
   import com.youku.adSDK.model.FrontProxy;
   import com.youku.adSDK.model.OverlayProxy;
   import com.youku.adSDK.model.BackProxy;
   import com.youku.adSDK.model.PauseProxy;
   import com.youku.adSDK.model.InsertProxy;
   import flash.net.registerClassAlias;
   import com.youku.adSDK.view.events.ADEvent;
   
   public class YoukuAdManager extends EventDispatcher
   {
      
      public function YoukuAdManager(param1:PrivateClass, param2:ADContext) {
         super();
         if(param1 != null)
         {
            this._adContext = param2;
            YoukuAdManager.context = this._adContext;
            this.init();
         }
      }
      
      private static var _instance:YoukuAdManager;
      
      public static var frontPlaying:Boolean = false;
      
      public static var frontOverTime:Number = -1;
      
      public static var adHoldMediator:AdHolderMediator;
      
      public static var context:ADContext;
      
      public static var debugTF:TextField;
      
      public static function debug_log(param1:String) : void {
         debugTF.text = param1;
      }
      
      public static function getInstance(param1:ADContext) : YoukuAdManager {
         if(_instance == null)
         {
            _instance = new YoukuAdManager(new PrivateClass(),param1);
         }
         return _instance as YoukuAdManager;
      }
      
      private var _frontMediator:FrontMediator;
      
      private var _backMediator:BackMediator;
      
      private var _pauseMediator:PauseMediator;
      
      private var _insertMediator:InsertMediator;
      
      private var _overlayMediator:OverlayMediator;
      
      private var _adHolderMediator:AdHolderMediator;
      
      private var _frontProxy:FrontProxy;
      
      private var _overlayProxy:OverlayProxy;
      
      private var _backProxy:BackProxy;
      
      private var _pauseProxy:PauseProxy;
      
      private var _insertProxy:InsertProxy;
      
      private var _adContext:ADContext;
      
      private var _eventDispather:ADEventDispather;
      
      private function init() : void {
         this._eventDispather = ADEventDispather.getInstance();
         this.registerSkin();
         this.addEvents();
         this._frontMediator = new FrontMediator(this._eventDispather,this._adContext);
         this._frontMediator.init();
         this._insertMediator = new InsertMediator(this._eventDispather,this._adContext);
         this._insertMediator.init();
         this._backMediator = new BackMediator(this._eventDispather,this._adContext);
         this._backMediator.init();
         this._pauseMediator = new PauseMediator(this._eventDispather,this._adContext);
         this._pauseMediator.init();
         this._overlayMediator = new OverlayMediator(this._eventDispather,this._adContext);
         this._overlayMediator.init();
         this._adHolderMediator = new AdHolderMediator(this._adContext.mainMc,this._eventDispather,this._adContext);
         this._adHolderMediator.init();
         YoukuAdManager.adHoldMediator = this._adHolderMediator;
      }
      
      private function registerSkin() : void {
         registerClassAlias("AD_btn",AD_btn);
         registerClassAlias("AD_closer",AD_closer);
         registerClassAlias("AD_holdInfo",AD_holdInfo);
         registerClassAlias("AD_changeInfo",AD_changeInfo);
         registerClassAlias("AD_resumeCloser",AD_resumeCloser);
         registerClassAlias("AD_holdTime",AD_holdTime);
      }
      
      public function loadBack() : void {
         this._eventDispather.dispatchEvent(new ADEvent(ADEvent.REQUEST_AND_PLAY_BACK_AD));
      }
      
      public function loadFront(param1:Boolean) : void {
         this._eventDispather.dispatchEvent(new ADEvent(ADEvent.REQUEST_AND_PLAY_FRONT_AD,{"skip":param1}));
      }
      
      public function setInsertPoints(param1:Array) : void {
         this._insertMediator.setPoints(param1);
      }
      
      public function setPlayerPanelStateChange(param1:Boolean) : void {
         this._eventDispather.dispatchEvent(new ADEvent(ADEvent.PANEL_STATE_CHANGE,{"havePanel":param1}));
      }
      
      public function setPlayerStartPlay() : void {
         this._eventDispather.dispatchEvent(new ADEvent(ADEvent.COMMON_START_TO_PLAY));
      }
      
      public function changeVolume(param1:Number) : void {
         this._eventDispather.dispatchEvent(new ADEvent(ADEvent.CHANGE_VOLUME,{"volume":param1}));
      }
      
      public function closeAd() : void {
         this._eventDispather.dispatchEvent(new ADEvent(ADEvent.COMMON_ERROR));
      }
      
      public function resetAd() : void {
         this._eventDispather.dispatchEvent(new ADEvent(ADEvent.COMMON_RESET));
      }
      
      public function setVideoPlayingTime(param1:Number, param2:Number) : void {
         this._eventDispather.dispatchEvent(new ADEvent(ADEvent.VIDEO_PLAYING,
            {
               "nsTime":param1,
               "ST":param2
            }));
      }
      
      public function setVideoEnd() : void {
         this._eventDispather.dispatchEvent(new ADEvent(ADEvent.VIDEO_END));
      }
      
      public function setControlbarHide() : void {
         this._eventDispather.dispatchEvent(new ADEvent(ADEvent.CONTROL_BAR_HIDE));
      }
      
      public function setControlbarShow() : void {
         this._eventDispather.dispatchEvent(new ADEvent(ADEvent.CONTROL_BAR_SHOW));
      }
      
      public function setInfobarShow() : void {
         this._eventDispather.dispatchEvent(new ADEvent(ADEvent.CONTROL_BAR_INFO_BAR_SHOW));
      }
      
      public function setInfobarHide() : void {
         this._eventDispather.dispatchEvent(new ADEvent(ADEvent.CONTROL_BAR_INFO_BAR_HIDE));
      }
      
      public function setScreenMode(param1:String, param2:Boolean) : void {
         this._eventDispather.dispatchEvent(new ADEvent(ADEvent.CHANGE_SCREEN_MODE,
            {
               "mode":param1,
               "tween":param2
            }));
      }
      
      public function setSize(param1:Number, param2:Number, param3:Number, param4:Boolean) : void {
         this._eventDispather.dispatchEvent(new ADEvent(ADEvent.CHANGE_SIZE,
            {
               "width":param1,
               "height":param2,
               "cheight":param3,
               "fullscreen":param4
            }));
      }
      
      public function setPlayerPause(param1:Boolean) : void {
         this._eventDispather.dispatchEvent(new ADEvent(ADEvent.PLAYER_PAUSE,{"useraction":param1}));
      }
      
      public function setPlayerResume() : void {
         this._eventDispather.dispatchEvent(new ADEvent(ADEvent.PLAYER_RESUME));
      }
      
      private function addEvents() : void {
         this._eventDispather.addEventListener(ADEvent.DO_FRONT,this.onADEvent);
         this._eventDispather.addEventListener(ADEvent.DO_OVERLAY,this.onADEvent);
         this._eventDispather.addEventListener(ADEvent.DO_BACK,this.onADEvent);
         this._eventDispather.addEventListener(ADEvent.DO_PAUSE,this.onADEvent);
         this._eventDispather.addEventListener(ADEvent.DO_INSERT,this.onADEvent);
         this._eventDispather.addEventListener(YoukuAdEvent.AD_LOAD_TIME,this.onADOtherEvent);
         this._eventDispather.addEventListener(YoukuAdEvent.AD_LOAD_TIME_REQUEST,this.onADOtherEvent);
         this._eventDispather.addEventListener(YoukuAdEvent.AD_FRONT_START_TO_PLAY,this.onADOtherEvent);
         this._eventDispather.addEventListener(YoukuAdEvent.AD_FRONT_LOAD_COMPLETE,this.onADOtherEvent);
         this._eventDispather.addEventListener(YoukuAdEvent.AD_VIDEO_PLAY_COMPLETE,this.onADOtherEvent);
         this._eventDispather.addEventListener(YoukuAdEvent.AD_BLOCK_NOTICE_REPORT,this.onADOtherEvent);
         this._eventDispather.addEventListener(YoukuAdEvent.AD_BLOCK_REPORT,this.onADOtherEvent);
         this._eventDispather.addEventListener(YoukuAdEvent.AD_FRONT_READY_OR_ERROR,this.onADOtherEvent);
         this._eventDispather.addEventListener(YoukuAdEvent.AD_HOLDER_SHOW,this.onADOtherEvent);
         this._eventDispather.addEventListener(YoukuAdEvent.AD_HOLDER_SHOW_IN_FRONT,this.onADOtherEvent);
         this._eventDispather.addEventListener(YoukuAdEvent.AD_SOUND_MUTE,this.onADOtherEvent);
         this._eventDispather.addEventListener(YoukuAdEvent.AD_VIDEO_PAID_SHOW,this.onADOtherEvent);
         this._eventDispather.addEventListener(YoukuAdEvent.AD_USER_ACTION,this.onADOtherEvent);
         this._eventDispather.addEventListener(YoukuAdEvent.AD_INSERT_POINT_LOADED,this.onADOtherEvent);
         this._eventDispather.addEventListener(YoukuAdEvent.AD_INSERT_REQUEST_TO_PLAY,this.onADOtherEvent);
         this._eventDispather.addEventListener(YoukuAdEvent.AD_INSERT_WILL_PLAY,this.onADOtherEvent);
         this._eventDispather.addEventListener(YoukuAdEvent.AD_PAUSE_NULL,this.onADOtherEvent);
         this._eventDispather.addEventListener(YoukuAdEvent.AD_PAUSE_HIDE,this.onADOtherEvent);
         this._eventDispather.addEventListener(YoukuAdEvent.AD_PAUSE_PLAY_BUTTON_CLICK,this.onADOtherEvent);
         this._eventDispather.addEventListener(YoukuAdEvent.AD_LOST_FOCUS,this.onADOtherEvent);
         this._eventDispather.addEventListener(YoukuAdEvent.AD_GET_FOCUS,this.onADOtherEvent);
         this._eventDispather.addEventListener(YoukuAdEvent.AD_SKIP_SHOW,this.onADOtherEvent);
      }
      
      private function onADOtherEvent(param1:YoukuAdEvent) : void {
         this.dispatchEvent(new YoukuAdEvent(param1.type,param1.data));
      }
      
      private function onADEvent(param1:ADEvent) : void {
         var _loc2_:* = 0;
         var _loc3_:* = NaN;
         var _loc4_:* = NaN;
         switch(param1.type)
         {
            case ADEvent.DO_FRONT:
               this._frontProxy = new FrontProxy();
               this._frontProxy.init(this._adContext);
               this._frontProxy.load(0);
               break;
            case ADEvent.DO_OVERLAY:
               _loc2_ = param1.data as int;
               this._overlayProxy = new OverlayProxy();
               this._overlayProxy.init(this._adContext,_loc2_);
               break;
            case ADEvent.DO_BACK:
               this._backProxy = new BackProxy();
               this._backProxy.init(this._adContext);
               break;
            case ADEvent.DO_PAUSE:
               if(!this._adContext.isTudouPlayer)
               {
                  this._pauseProxy = new PauseProxy();
                  this._pauseProxy.init(this._adContext);
               }
               break;
            case ADEvent.DO_INSERT:
               _loc3_ = param1.data.time;
               _loc4_ = param1.data.no;
               this._insertProxy = new InsertProxy();
               this._insertProxy.init(this._adContext,_loc3_,_loc4_);
               break;
         }
      }
   }
}
class PrivateClass extends Object
{
   
   function PrivateClass() {
      super();
   }
}
